package com.ym9527.controller;


import com.ym9527.entity.User;
import com.ym9527.jpa.UserJpa;
import com.ym9527.utils.R;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("user")
public class UserController {


    @Resource
    UserJpa userJpa;

    @PostMapping("login")
    @Transactional()
    public R UserLogin(@RequestBody User user){

        User user1=userJpa.findByUserName(user.getUserName());

        if(null!=user1){

            if(user1.getPassword().equals(user.getPassword())){

                return R.ok(user1);

            }else{

                return R.error("登录失败,密码错误");

            }


        }


        return R.error("登录失败,账号不存在");
    }


}
